<script>
import { generateFingerPrint } from "@/utils/fingerprint";
import {FINGER_PRINT} from "@/utils/constant";
export default {
	onLaunch: function () {
		// 获取设备信息、窗口信息、应用信息生成指纹信息，用于coze会话隔离
		let fingerPrint = ''
		if (!uni.getStorageSync(FINGER_PRINT)) {
			const windowInfo = uni.getWindowInfo()
			const deviceInfo = uni.getDeviceInfo()
			const appBaseInfo = uni.getAppBaseInfo()
			
			fingerPrint = generateFingerPrint(windowInfo, deviceInfo, appBaseInfo)
			uni.setStorageSync(FINGER_PRINT, fingerPrint)
		} else {
			fingerPrint = uni.getStorageSync(FINGER_PRINT)
		}
		this.$store.dispatch('setCozeAccessToken', fingerPrint)

		const updateManager = uni.getUpdateManager();

		updateManager.onCheckForUpdate(function (res) {
			// 请求完新版本信息的回调
			console.log(res.hasUpdate);
		});

		updateManager.onUpdateReady(function (res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});

		});

		updateManager.onUpdateFailed(function (res) {
			// 新的版本下载失败
		});
	},
	onShow: function () {
		console.log('App Show')
	},
	onHide: function () {
		console.log('App Hide')
	}
}
</script>

<style>
/*每个页面公共css */
</style>
